package com.ruoyi.system.service.impl;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.Threads;
import com.ruoyi.common.utils.baidu.BaiduMapUtil;
import com.ruoyi.common.utils.RTTCalculator;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.baidu.GeoUtils;
import com.ruoyi.system.common.BaseData;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.handler.ReceDataServiceHandler;
import com.ruoyi.system.mapper.*;
import com.ruoyi.system.service.ReceDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.time.ZoneId;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author: jkk
 * @create: 2025/3/9-20:56
 * @Description:
 */
@Service
public class ReceDataServiceImpl implements ReceDataService {

    private static final Logger logger = LoggerFactory.getLogger(ReceDataServiceImpl.class);

    @Autowired
    private TDeviceMapper tDeviceMapper;

    @Autowired
    private ReceDataServiceHandler receDataServiceHandler;
    @Override
    public  String processPosition(Map<String, Object> map) throws Exception {
        logger.info("接收到数据：{}", map.toString());
        JSONObject retObj = new JSONObject();
        retObj.put("uploadInterval","");
        retObj.put("enableSatelliteLocat","");
        retObj.put("enableExtendLocat","");
        //@TODO 获取设备信息
        TDevice tDevice = tDeviceMapper.selectTDeviceByDeviceNumber(map.get("id").toString());
        if(tDevice != null){
            //塞到map中
            map.put("deviceName",tDevice.getDeviceName());
            map.put("uploadInterval",tDevice.getUploadInterval());
            //tLocationData.setDeviceName(tDevice.getDeviceName());
            //tLocationData.setReportInterval(tDevice.getUploadInterval());
            retObj.put("uploadInterval",tDevice.getUploadInterval());
            retObj.put("enableSatelliteLocat",tDevice.getEnableSatelliteLocat());
            retObj.put("enableExtendLocat",tDevice.getEnableExtendLocat());
            // 异步处理耗时操作
            receDataServiceHandler.processPositionAsync(map);
        }
        return retObj.toString();
    }


}
